package com.tnt.springbootrabbmitmq.provider.topicexchange;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description 主题类型交换机配置, 交换机名称、队列名称、路由key是三个不同的值。
 * @Author zhuangxl
 * @Date 2021-01-24 15:49
 */
@Configuration
public class TopicExchangeRabbitMqConfig {


    /**
     * @Description: 定义队列
     * @Author: zhuangxl
     * @Date: 21/1/24 19:21
     * @return: org.springframework.amqp.core.Queue
     **/
    @Bean
    public Queue topicExchangeQueue1(){

        return new Queue("topicExchangQueue1");

    }

    /**
     * @Description: 定义队列
     * @Author: zhuangxl
     * @Date: 21/1/24 19:21
     * @return: org.springframework.amqp.core.Queue
     **/
    @Bean
    public Queue topicExchangeQueue2(){

        return new Queue("topicExchangQueue2");

    }

    /**
     * @Description: 定义交换机
     * @Author: zhuangxl
     * @Date: 21/1/24 19:21
     * @return: org.springframework.amqp.core.TopicExchange
     **/
    @Bean
    public TopicExchange topicExchange(){

        return new TopicExchange("tipicExchange");

    }

    /**
     * @Description: 绑定队列到交换机并指定路由key
     * @Author: zhuangxl
     * @Date: 21/1/24 19:22
     * @return: org.springframework.amqp.core.Binding
     **/
    @Bean
    Binding bindingTopicExchangeMessage1(){

        return BindingBuilder.bind(topicExchangeQueue1()).to(topicExchange()).with("topicExchangeRoutingKey.1");

    }

    /**
     * @Description: 绑定队列到交换机并定义路由规则
     * @Author: zhuangxl
     * @Date: 21/1/24 19:23
     * @return: org.springframework.amqp.core.Binding
     **/
    @Bean
    Binding bindingTopicExchangeMessage2(){

        return BindingBuilder.bind(topicExchangeQueue2()).to(topicExchange()).with("topicExchangeRoutingKey.#");

    }
    
}
